//
//  GJGCChatFriendPersonalCardCell.m
//  LEVE
//
//  Created by 上官惠阳 on 2017/3/18.
//  Copyright © 2017年 dashuju. All rights reserved.
//

#import "GJGCChatFriendPersonalCardCell.h"

@interface GJGCChatFriendPersonalCardCell ()
@property (nonatomic,assign)CGFloat contentInnerMargin;
@property (nonatomic,strong)UIView *contentVi;
@end

@implementation GJGCChatFriendPersonalCardCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        self.bubbleBackImageView.layer.borderColor = GJCFQuickRGBColor(241,242,244).CGColor;
        self.bubbleBackImageView.layer.borderWidth = 1;

        self.contentInnerMargin = 11.f;
        self.contentVi = [[UIView alloc] init];
        self.contentVi.backgroundColor = [UIColor whiteColor];
        [self.bubbleBackImageView addSubview:self.contentVi];

        self.headImgView = [[UIImageView alloc]init];
        self.headImgView.gjcf_size = (CGSize){44,44};
        self.headImgView.layer.masksToBounds = YES;
        self.headImgView.layer.cornerRadius = 22;
        self.headImgView.userInteractionEnabled = YES;
        [self.bubbleBackImageView addSubview:self.headImgView];

        self.preNameLabel = [[UILabel alloc]init];
        self.preNameLabel.font = [UIFont systemFontOfSize:14];
        self.preNameLabel.textColor = [UIColor blackColor];
        [self.bubbleBackImageView addSubview:self.preNameLabel];

        self.detailLabel = [[UILabel alloc]init];
        self.detailLabel.font = [UIFont systemFontOfSize:12];
        self.detailLabel.textColor = GJCFQuickRGBColor(177,183,201);
        [self.bubbleBackImageView addSubview:self.detailLabel];

        UITapGestureRecognizer *tapR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapOnSelf)];
        tapR.numberOfTapsRequired = 1;
        [self.bubbleBackImageView addGestureRecognizer:tapR];
    }
    return self;
}

- (void)setContentModel:(GJGCChatContentBaseModel *)contentModel
{
    GJGCChatFriendContentModel *chatModel = (GJGCChatFriendContentModel *)contentModel;

    [super setContentModel:chatModel];

    self.preNameLabel.gjcf_width = 178 - 3*self.contentInnerMargin - self.headImgView.gjcf_width;
    self.preNameLabel.text = chatModel.preName;
    self.preNameLabel.gjcf_height = 17.f;

    self.detailLabel.gjcf_width = 178 - 3*self.contentInnerMargin - self.headImgView.gjcf_width;
    self.detailLabel.text = chatModel.preDetail;
    self.detailLabel.gjcf_height = 15.f;

    [self.headImgView sd_setImageWithURL:[NSURL URLWithString:chatModel.preHeadUrl] placeholderImage:[UIImage imageNamed:@"avatar_user"]];

    self.bubbleBackImageView.gjcf_height = 70;
    self.bubbleBackImageView.gjcf_width = 178;

    self.contentVi.frame = CGRectMake(0, 0, 178, 70);

    self.headImgView.gjcf_left = self.contentBordMargin;
    self.headImgView.gjcf_centerY = self.bubbleBackImageView.centerY;

    self.preNameLabel.gjcf_left = self.headImgView.gjcf_right + self.contentBordMargin-5;
    self.preNameLabel.gjcf_top = self.headImgView.gjcf_top + 3.f;


    self.detailLabel.gjcf_left = self.headImgView.gjcf_right + self.contentBordMargin-5;
    self.detailLabel.gjcf_top = self.preNameLabel.gjcf_bottom + 3;


    [self adjustContent];
}

#pragma mark - 长按事件继承

- (void)goToShowLongPressMenu:(UILongPressGestureRecognizer *)sender
{
    [super goToShowLongPressMenu:sender];

    UIMenuController *popMenu = [UIMenuController sharedMenuController];
    if (popMenu.isMenuVisible) {
        return;
    }

    UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(deleteMessage:)];
    NSArray *menuItems = @[item2];
    [popMenu setMenuItems:menuItems];
    [popMenu setArrowDirection:UIMenuControllerArrowDown];

    [popMenu setTargetRect:self.bubbleBackImageView.frame inView:self];
    [popMenu setMenuVisible:YES animated:YES];
}

- (void)tapOnSelf
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(presonalCardMessageCellDidTap:)]) {

        [self.delegate presonalCardMessageCellDidTap:self];
    }
}
@end
